package com.nj.user.controller;

import com.nj.bean.Result;
import com.nj.user.entity.dto.UserDto;
import com.nj.user.entity.req.UserPageReq;
import com.nj.user.entity.req.UserReq;
import com.nj.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("")
    public Result addUser(@RequestBody UserReq userReq){
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userReq,userDto);
        return Result.ok(userService.addUser(userDto));
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        return Result.ok(userService.delete(id));
    }
    @GetMapping
    public Result getUserPage(@RequestBody UserPageReq userPageReq){
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userPageReq,userDto);
        return Result.ok(userService.getPageResult(userDto));
    }
}
